import Vue from "vue"
import axios from "axios"
if (process.env.NODE_ENV === 'production') {
  axios.defaults.baseURL = "/api"
  Vue.prototype.$formatImg = "http://101.132.124.188:10000"
} else {
  Vue.prototype.$formatImg = "http://localhost:10000/"
  axios.defaults.baseURL = "/api"

}
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
// 添加请求拦截器
axios.interceptors.request.use(
  config => {
    Nprogress.start()
    let token = localStorage.getItem("token")
    if (token) {
      config.headers.token = token
    }
    return config
  },
  error => {
    console.log(`err`, error)
  }
)
// 响应请求拦截器
axios.interceptors.response.use(res => {
  console.log(`mainres`, res)
  Nprogress.done()

  return res
}, err => {

})
Vue.prototype.$http = axios